/**
 * @author wItspirit
 * 29-mei-2005
 * MockFlickrApi.java
 */

package org.scohen.juploadr.flickr;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.List;

import org.eclipse.swt.widgets.Decorations;
import org.scohen.juploadr.app.ImageAttributes;
import org.scohen.juploadr.app.JUploadr;
import org.scohen.juploadr.app.PhotoSet;
import org.scohen.juploadr.app.UploadImage;
import org.scohen.juploadr.event.ImageUploadResponse;
import org.scohen.juploadr.event.UploadCompleteEvent;
import org.scohen.juploadr.event.UploadEvent;
import org.scohen.juploadr.event.UploadStatusMonitor;
import org.scohen.juploadr.ui.PopupHandler;
import org.scohen.juploadr.uploadapi.Account;
import org.scohen.juploadr.uploadapi.AuthException;
import org.scohen.juploadr.uploadapi.CommunicationException;
import org.scohen.juploadr.uploadapi.ImageUploadApi;
import org.scohen.juploadr.uploadapi.ProtocolException;
import org.scohen.juploadr.uploadapi.UploadFailedException;

/**
 * This is a Mock implementation of the FlickrApi
 */
public class MockFlickrApi extends ImageUploadApi {
    private Account flickrUserInfo;

    public class FlickrUserInfoImpl extends Account {
        private String password;
        private boolean isPro;
        private long monthlyLimit;
        private long used;

        public FlickrUserInfoImpl(String username, String password, boolean isPro, long monthlyLimit, long used) {
            super(username);
            this.username = username;
            this.password = password;
            this.isPro = isPro;
            this.monthlyLimit = monthlyLimit;
            this.used = used;
        }

        public String getUsername() {
            return username;
        }

        public String getPassword() {
            return password;
        }

        public boolean isPro() {
            return isPro;
        }

        public long getMonthlyUploadLimit() {
            return monthlyLimit;
        }

        public long getCurrentUploadUsed() {
            return used;
        }

        public URL getPhotoURL() {
            try {
                return new URL("http://www.google.com");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        public ImageUploadApi getApi() {
            return MockFlickrApi.getInstance();
        }

    }

    public boolean isCurrentAccountNullAccount() {
       return false;
    }

    /**
     * 
     */
    public MockFlickrApi() {
        flickrUserInfo = new FlickrUserInfoImpl("mockUser", "mockPassword", true, 10000000000L, 1000000000L);
    }

    public String getSiteName() {
        return "MockFlickr";
    }

    /**
     * @see org.scohen.juploadr.flickr.FlickrApi#authenticate(java.lang.String,
     *      java.lang.String)
     */
    public Account authenticate(String username) throws AuthException {
        if (username.equals(flickrUserInfo.getName())) {
            return flickrUserInfo;
        } else {
            throw new AuthException("Invalid username or password");
        }
    }

    /**
     * @see org.scohen.juploadr.flickr.FlickrApi#upload(org.scohen.juploadr.flickr.FlickrUserInfo,
     *      org.scohen.juploadr.app.UploadImage,
     *      org.scohen.juploadr.event.UploadStatusMonitor)
     */
    public void upload(Account userInfo, UploadImage imageAttributes, UploadStatusMonitor monitor)
            throws UploadFailedException {
        monitor.uploadStarted(new UploadEvent(imageAttributes, 0, true, false));
        try {
            // Just wait a bit
            Thread.sleep(3000);
        } catch (InterruptedException e) {
        }
        monitor.uploadFinished(new UploadCompleteEvent(new ImageUploadResponse("1234"), null));
    }

    public Account authenticate() throws ProtocolException, CommunicationException {
        // TODO Auto-generated method stub
        return null;
    }

    public void upload(UploadImage imageAttributes, UploadStatusMonitor monitor) throws UploadFailedException,
            CommunicationException {
        // TODO Auto-generated method stub

    }

    public Class[] getConfiurationDialogs() {
        // TODO Auto-generated method stub
        return null;
    }

    public PopupHandler windowRightClicked(Decorations parent, JUploadr clicked) {
        // TODO Auto-generated method stub
        return null;
    }

    public PopupHandler thumbnailRightClicked(Decorations parent, JUploadr uploadr, ImageAttributes clicked) {
        // TODO Auto-generated method stub
        return null;
    }

    public void postProcessUpload(UploadCompleteEvent e, ImageAttributes atts) {
        // TODO Auto-generated method stub

    }

    public void postProcessAllUploads(Collection collection) {
        // TODO Auto-generated method stub

    }

    public void initialize() {

    }

    public Account getCurrentAccount() {
        // TODO Auto-generated method stub
        return null;
    }

    public Account newAccount(String name) {
        // TODO Auto-generated method stub
        return null;
    }

    public void setCurrentAccount(Account account) {
        // TODO Auto-generated method stub

    }

    public boolean authenticate(Account toAuthenticate) throws ProtocolException, CommunicationException {
        // TODO Auto-generated method stub
        return false;
    }

    public List<? extends Account> allAccounts() {

        return null;
    }

    public void cancelUpload() {
        // TODO Auto-generated method stub
        
    }

    public PhotoSet newPhotoSet(ImageAttributes primaryPhoto) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public PhotoSet newPhotoSet(String name, String description, ImageAttributes primaryPhoto) {
        // TODO Auto-generated method stub
        return null;
    }

}
